package com.springstudy.controller;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.springstudy.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Tamako
 * @since 2025/1/13 16:07
 */
//@Controller
//@ResponseBody
@RestController
public class ResponseController2 {
    @RequestMapping("/ajax/req3")
    public User res3() {
        User user = new User();
        user.setUsername("Tamako");
        user.setAge(20);
        return user;
    }

    @RequestMapping("/ajax/req2")
    public String res2() throws Exception {
        User user = new User();
        user.setUsername("Tamako");
        user.setAge(25);
        ObjectMapper objectMapper = new ObjectMapper();
        return objectMapper.writeValueAsString(user);
    }


}
